/*
 * AccountTransactionsUpdateTests.java
 *
 *  
 */
package org.msb.finance.data;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import java.math.BigDecimal;
import java.util.Date;

import org.junit.Before;
import org.junit.Test;

/**
 * 
 * 
 * @author Marc Boudreau
 * 
 */
public class AccountTransactionsUpdateTests {

	/*
	 * 
	 */
	private AccountTransactionsUpdate update;

	/**
	 * @throws Exception
	 */
	@Before
	public void setUp() throws Exception {
		update = new AccountTransactionsUpdate();
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testConstructor() throws Exception {
		assertNotNull(update);
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testGetDefaultDate() throws Exception {
		assertNull(update.getDate());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetDate() throws Exception {
		final Date DATE = new Date();
		update.setDate(DATE);

		assertEquals(DATE, update.getDate());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetDateToNull() throws Exception {
		update.setDate(null);
		assertNull(update.getDate());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testGetDefaultBalance() throws Exception {
		assertNull(update.getBalance());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetBalance() throws Exception {
		final BigDecimal BALANCE = new BigDecimal(9873.342);
		update.setBalance(BALANCE);
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetBalanceToNull() throws Exception {
		update.setBalance(null);
		assertNull(update.getBalance());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetBalanceToNegative() throws Exception {
		final BigDecimal BALANCE = new BigDecimal(-349.45);
		update.setBalance(BALANCE);

		assertEquals(BALANCE, update.getBalance());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testGetTransactionCount() throws Exception {
		assertEquals(0, update.getTransactionCount());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testAddTransaction() throws Exception {
		final Transaction TX = new Transaction();
		update.addTransaction(TX);

		assertEquals(1, update.getTransactionCount());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testAddNullTransaction() throws Exception {
		update.addTransaction(null);

		assertEquals(0, update.getTransactionCount());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testAddSameTransactionTwice() throws Exception {
		final Transaction TX = new Transaction();
		update.addTransaction(TX);
		update.addTransaction(TX);

		assertEquals(2, update.getTransactionCount());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testRemoveTransaction() throws Exception {
		final Transaction TX = new Transaction();
		update.addTransaction(TX);

		update.removeTransaction(TX);
		assertEquals(0, update.getTransactionCount());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testRemoveNonExistingTransaction() throws Exception {
		final Transaction TX1 = new Transaction();
		final Transaction TX2 = new Transaction();
		update.addTransaction(TX1);

		update.removeTransaction(TX2);
		assertEquals(1, update.getTransactionCount());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testRemoveNullTransaction() throws Exception {
		update.removeTransaction(null);

		assertEquals(0, update.getTransactionCount());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testRemoveSameTransactionTwice() throws Exception {
		final Transaction TX1 = new Transaction();
		final Transaction TX2 = new Transaction();
		update.addTransaction(TX1);
		update.addTransaction(TX2);

		update.removeTransaction(TX2);
		assertEquals(1, update.getTransactionCount());

		update.removeTransaction(TX2);
		assertEquals(1, update.getTransactionCount());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testGetTransactions() throws Exception {
		assertNotNull(update.getTransactions());
	}
}
